package J_exercise;

public class Ex5_OOP4 {


	public static void main(String[] args) 
	{
		RetangleVO revo=new RetangleVO(4,10,"blue");
		float area=RetangleService.getArea(revo.width,revo.height);
		System.out.println("면적"+area+","+"색상"+revo.color);
		float perimeter=RetangleService.getPerimeter(revo.width, revo.height);
		System.out.println("둘레"+perimeter);
		System.out.println();
		
		FanVO Fanvo=new FanVO(false,FanVO.fast,15,"white");
//		FanVO Fanvo1=new FanVO(false,new FanVO().fast,15,"white"); 
		//이것도가능은함. 하지만 별로 좋지않음
		
		String a=FanService.toSting(Fanvo.on,Fanvo.speed,Fanvo.radius,Fanvo.color);
		System.out.println(a);
		
		
		
		
		System.out.println();
		AccountVO accvo=new AccountVO(1122, 20000, 4.5F,"2013-11-07 05:37");
		System.out.println("잔액="+accvo.balance);
		
		accvo.balance=AccountService.withDraw(accvo, 2500);
		System.out.println("인출후 잔액"+accvo.balance);
		accvo.balance=AccountService.deposit(accvo, 3000);
		System.out.println("예금후 잔액"+accvo.balance);
		float MonthrlyInterestRate=AccountService.getMonthrlyInterestRate(accvo.interestRate);
		System.out.println("월간이자율 "+MonthrlyInterestRate);
		
		System.out.println();
		StockVO stock1=new StockVO("경영기술", 1_000_000,750_000);
		float percent=StockService.getChangePercent(stock1.previousClosingPrice, stock1.currentPrice);
		System.out.println("경영기술 주가변동율\n"+percent+"%");

	}//end of main

}
class RetangleVO  //사각형 값을 저장하는 클래스
{
	float width,height;
	String color;
	
	public RetangleVO() // 기본생성자
	{
		width=1.0f;
		height=1.0f;
		color="white";
	}
	
	
	public RetangleVO(float width,float height,String color) 
	{
		this.width=width;
		this.height=height;
		this.color=color;
	}
	
}
class RetangleService
{
	static float getArea(float width,float height)
	{
		return width*height;
	}
	static float getPerimeter(float width,float height)
	{
		return (width+height)*2;
	}
	
}

class FanVO
{
//상수들은 객체 생성없이 바로 사용가능해야 하므로 따라서,static final이라는 예약어사용
//한편 JDK5이상에서는 이것을 대체하기위해 Enum이라는 새로운 클래스 자료형이 추가됨	
	static final int slow=1;
	static final int medium=2;
	static final int fast=3;
	boolean on;
	float radius;
	String color;
	int speed;
	public FanVO() {
		on=false;
		speed=slow;
		radius=5.0f;
		color="blue";
	}
	
	
	
	public FanVO(boolean on,int speed,float radius,String color) 
	{
		this.on=on;
		this.radius=radius;
		this.color=color;
		this.speed=speed;
	}
	

	
}
class FanService
{
	//모든정보 출력메소드
	static String toSting(boolean on,int speed,float radius,String color)
	{
		if(on)
			return "회전속도"+speed+"색상"+	color+"지름"+radius+"작동중";
		else
			return "회전속도"+speed+"색상"+	color+"지름"+radius+"정지";
	}
	
	//메서드 다중정의 overloading
	//서명만 다르면 메서드 이름은 동일하게
	/*
	static String showFanInfo(FanVO f)
	{
		
		
	
	}*/
	
}
class AccountVO
{
	int aid;
	int balance;
	float interestRate;
	String dateCreated;
	public AccountVO()
	{
		aid=0;
		balance=0;
		interestRate=0;
		
	}
	public AccountVO(int aid,int balance,float interestRate,String dateCreated)
	{
		this.aid=aid;
		this.balance=balance;
		this.interestRate=interestRate;
		this.dateCreated=dateCreated;
	}
	
}
class AccountService
{
	static float getMonthrlyInterestRate(float interestRate)
	{
		return interestRate/12;
	}
	static int withDraw(AccountVO a,int gold)
	{
		a.balance-=gold;
		return a.balance; 
		/*
		
		 메서드의 매개변수 유형이 기본 자료형일 경우 
		 기본자료형 값을 메서드매개변수로 전달하면 JVM은 메서드
		 지역변수에 그값 복사, 따라서 메서드의 지역변수 값을 변경하더라도
		 전달해준 변수는 영향을 미치지 않음.
		 */
	}
	static int deposit(AccountVO a,int gold)
	{
		a.balance+=gold;
				return a.balance;
	}
	
}
class StockVO
{
	String sname;
	float previousClosingPrice;
	float currentPrice;
	public StockVO() {}
	public StockVO(String sname,float previousClosingPrice,float currentPrice)
	{
		this.sname=sname;
		this.previousClosingPrice=previousClosingPrice;
		this.currentPrice=currentPrice;
	}
	
	
}
class StockService
{
	static float getChangePercent(float previousClosingPrice,float currentPrice)
	{
		float percent=(currentPrice-previousClosingPrice)/previousClosingPrice*100;
		return percent;
	}
	
}


